package com.yc.demo.d0301;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AddDataServlet", value = "/AddDataServlet")
public class AddDataServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String data = request.getParameter("data");
        //将数据保存到请求对象中
        request.setAttribute("data",data);
        //将数据保存到会话对象中
        //从请求中获取会话对象
        final HttpSession session = request.getSession();
        session.setAttribute("data",data);
        response.getWriter().printf("数据保存成功");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
